using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using B.S.Data.MES.API.Applications.CangKu.Command;

namespace B.S.Data.MES.API.Applications.CangKu.CommandHandlers
{
    public class UpdateCangKuCommandHandler : IRequestHandler<UpdateCangKuCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<CangKuinfo> _cangKuRepository;
        private readonly IMapper _mapper;

        public UpdateCangKuCommandHandler(IBaseRepository<CangKuinfo> cangKuRepository, IMapper mapper)
        {
            _cangKuRepository = cangKuRepository;
            _mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(UpdateCangKuCommand request, CancellationToken cancellationToken)
        {
            var cangKu = _mapper.Map<CangKuinfo>(request);
            cangKu.UpdateTime = DateTime.Now;
            cangKu.CreateTime =DateTime.Now;
            await _cangKuRepository.Update(cangKu);
            
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}